#include "stdafx.h"
#include "SceneMgr.h"


static SceneMgr *s_sceneMgr = nullptr;

SceneMgr* SceneMgr::GetInstance()
{
	if (!s_sceneMgr)
	{
		s_sceneMgr = new SceneMgr();
		//s_sceneMgr->init();
	}

	return s_sceneMgr;
}

SceneMgr::SceneMgr()
{
	m_runningScene = nullptr;
	m_scenesStack.reserve(15);
}

SceneMgr::~SceneMgr()
{
	m_runningScene = nullptr;
	m_scenesStack.clear();
}

void SceneMgr::ReplaceScene(std::shared_ptr<Scene> scene)
{
	if (m_scenesStack.size()) m_scenesStack.pop_back();
	m_scenesStack.push_back(scene);
	m_runningScene = scene;
}

void SceneMgr::PushScene(std::shared_ptr<Scene> scene)
{
	m_scenesStack.push_back(scene);
	m_runningScene = scene;
}

void SceneMgr::PopScene()
{
	if (m_scenesStack.size()) m_scenesStack.pop_back();
	if (m_scenesStack.size()) m_runningScene = m_scenesStack.back();
}

void SceneMgr::PopToRootScene()
{
	for (int i = 0; i < m_scenesStack.size() - 1; i++)
	{
		m_scenesStack.pop_back();
	}
	if (m_scenesStack.size()) m_runningScene = m_scenesStack.back();
}

std::shared_ptr<Scene> SceneMgr::GetRunningScene()
{
	return m_runningScene;
}

void SceneMgr::End()
{
	m_runningScene = nullptr;
	m_scenesStack.clear();
}
